<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>页面的跳转</title>
    <style>
        p{
            text-align: center;
        }
        span{
            color: red;
        }
    </style>
</head>
<body>
    <p>
        <span id="time">5</span>秒之后，自动跳转到首页.....
    </p>
</body>
</html>
<script>
    var time = document.getElementById("time");
    var number=5;
    function f() {
        number--;
        if (number<0){
            location.href="http://www.baidu.com";
            return;
        }
        time.innerHTML=number+"";

    }
    //设置定时器，每一秒执行一次函数
    setInterval(f,1000);
</script>